package com.cqc.slidingmenudmeo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.cqc.slidingmenudmeo.R;
import com.cqc.slidingmenudmeo.activity.MainActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cui on 2016/9/25.
 */
public class RightMenuFragment extends Fragment {


    private Context context;
    private View rootView;
    private ListView listView;
    private List<BaseFragment> list = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getContext();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_menu_right, container, false);
        listView = (ListView) rootView.findViewById(R.id.listView_right);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        String[] array = {"item1","item2","item3","item4"};
        listView.setAdapter(new ArrayAdapter(context,android.R.layout.simple_list_item_1,array));
        initData();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ((MainActivity)getActivity()).switchFragment(list.get(i));
            }
        });
    }


    private void initData() {
        list.clear();
        Fragment1 fragment1 = new Fragment1();
        Fragment2 fragment2 = new Fragment2();
        Fragment3 fragment3 = new Fragment3();
        Fragment4 fragment4 = new Fragment4();
        list.add(fragment1);
        list.add(fragment2);
        list.add(fragment3);
        list.add(fragment4);
    }
}
